package com.imut.onlinebanking.dealings.controller;

import com.imut.onlinebanking.base.response.JsonResult;
import com.imut.onlinebanking.base.response.StatusCode;
import com.imut.onlinebanking.dealings.entity.Account;
import com.imut.onlinebanking.dealings.service.AccountsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@RequestMapping("/deposit")
public class DepositController {

    @Autowired
    private AccountsService accountService;

    @PostMapping
    public JsonResult deposit(@RequestParam Long accountId, @RequestParam BigDecimal amount) {
        boolean result = accountService.deposit(accountId, amount);
        if (result) {
            return JsonResult.ok("存款成功");
        } else {
            return new JsonResult(StatusCode.OPERATION_FAILED.getCode(), "存款失败，余额不足或账户不存在", null);
        }
    }

    @GetMapping("/deposit/success")
    public String showDepositSuccess(Model model) {
        Account account = accountService.getAccountById(1L); // 假设当前用户ID为1
        model.addAttribute("account", account);
        return "depositSuccess";
    }
}

